home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 352_01.zip / STRPPTRN.CPP < prev    next >
C/C++ Source or Header  |  1993-04-10  |  755b  |  26 lines

  1. // STRPPTRN.CPP      contains String::translate()
  2. //             NOTE: construction of loop guarantees against NULL strings
  3. //                    (as long as the length field is 0 for them)
  4. //                    but does not guarantee against NULL translation strings.
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "dblib.h"
  8.  
  9. String& String::translate ( char *a, char *b )
  10.     {
  11.     int sn     =n;
  12.     char *ss=s;
  13.     int  al = strlen (a);
  14.     int i;
  15.     _NORMALIZE (b, char*);
  16.     while ( --sn >= 0 )            // run backwards through string.
  17.         {
  18.         if ( -1 != ( i= findchr ( a, al, ss[sn] ) ) )
  19.             {
  20.             //  found char from string a in position i within String this->s
  21.             //  so replace it with equivalent char from b.        
  22.             ss[sn] = b[i];        
  23.             } 
  24.         }
  25.     return *this;    
  26.     }        // end of String::translate()